import request from '@/utils/request';



export function homeConfig() {
    return request({
        url: '/api/homeConfig',
        method: 'get',
        data: null
    });
}







export function fetchList(params) {
    return request({
        url: '/api/article/home/list',
        method: 'post',
        data: params
    });
}

// UV信息

export function siteInfo() {
    return request({
        url: '/api/siteInfo',
        method: 'get',
        data: null
    });
}


export function pub() {
    return request({
        url: '/api/pub',
        method: 'get',
        data: null
    });
}

export function getEmailCode(params) {
    return request({
        url: '/api/sendEmail',
        method: 'get',
        params: params
    });
}


export function getVeriCode() {
    return request({
        url: '/api/user/getVeriCode',
        method: 'get',
        data: null
    });
}






export function login(params) {
    return request({
        method: 'post',
        url: '/api/login',
        data: params,
        transformRequest: [
            function(data) {
                let ret = '';
                for (let i in data) {
                    //往ret上面追加变量
                    ret += encodeURIComponent(i) + '=' + encodeURIComponent(data[i]) + '&';
                }
                return ret;
            }
        ],
        //定义header
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded '
        }
    });
}


export function emaillogin(params) {
    return request({
        method: 'post',
        url: '/api/email/login',
        data: params,
        transformRequest: [
            function(data) {
                let ret = '';
                for (let i in data) {
                    //往ret上面追加变量
                    ret += encodeURIComponent(i) + '=' + encodeURIComponent(data[i]) + '&';
                }
                return ret;
            }
        ],
        //定义header
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded '
        }
    });
}

export function logout(params) {
    return request({
        method: 'post',
        url: '/api/logout',
        data: params,
        transformRequest: [
            function(data) {
                let ret = '';
                for (let i in data) {
                    //往ret上面追加变量
                    ret += encodeURIComponent(i) + '=' + encodeURIComponent(data[i]) + '&';
                }
                console.log(ret);
                return ret;
            }
        ],
        //定义header
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded '
        }
    });
}

export function getArticle(params) {
    return request({
        url: '/api/article/common/getArticleById',
        method: 'get',
        params: params
    });
}




export function getComments(params) {
    return request({
        url: '/api/comment/home/list',
        method: 'post',
        data: params
    });
}

export function comments(params) {
    return request({
        url: '/api/comment/comments',
        method: 'post',
        data: params
    });
}

export function getReplys(params) {
    return request({
        url: '/api/comment/home/replys',
        method: 'post',
        data: params
    });
}

export function fetchFocus() {
    return request({
        url: '/api/article/home/hots',
        method: 'get',
        params: {}
    });
}

export function like(params) {
    return request({
        url: '/api/article/home/articleUp',
        method: 'get',
        params: params
    });
}

export function fetchCategory() {
    return request({
        url: '/api/category/admin/list',
        method: 'get',
        params: {}
    });
}

// 评论点赞
export function commentLike(params) {
    return request({
        url: '/api/comment/like',
        method: 'get',
        params: params
    });
}

export function fetchFriend() {
    return request({
        url: '/friend',
        method: 'get',
        params: {}
    });
}

export function fetchSocial() {
    return request({
        url: '/api/social',
        method: 'get',
        params: {}
    });
}

export function fetchSiteInfo() {
    return request({
        url: '/api/',
        method: 'get',
        params: {}
    });
}

export function fetchComment() {
    return request({
        url: '/comment',
        method: 'get',
        params: {}
    });
}